<?php date_default_timezone_set('America/New_York'); ?>

<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.progressbar.min.js"></script>
<script type="text/javascript">
var handle;
function updateProgress(data)
{
//	$("#uploadprogressbar").progressBar(data);
	if(data==false||data['done'])
	{
		$("#uploadprogressbar").progressBar(100);
		self.clearInterval(handle);
	}
	else
	{
		$("uploadprogressbar").progressBar(floor(parseInt(data['current'])/parseInt(data['total'])));
	}
}
 
 
// this sets up the progress bar
$(document).ready(function() {
	$("#uploadprogressbar").progressBar();
});
 
// fades in the progress bar and starts polling the upload progress after 1.5seconds
function beginUpload() {
	$("#uploadprogressbar").fadeIn();
	setTimeout("showUpload()", 150);
}
 
// uses ajax to poll the uploadprogress.php page with the id
// deserializes the json string, and computes the percentage (integer)
// update the jQuery progress bar
// sets a timer for the next poll in 750ms
var id='<?php echo $latestVersion->guid; ?>';
function showUpload() {
	$.ajax({
	       url: '<?php echo CController::createUrl('site/uploadFile');?>',
	       type: 'get',
	       dataType: 'json',
	       data: {uid:id},
	       success: updateProgress
	     });
}
</script>
<?php
	echo "GUID: ".$latestVersion->guid;
	echo "<br />";
	echo "VERSION: ".($latestVersion->version+1);
?>
<?php $form = $this->beginWidget('CActiveForm', array(
		'id'=>'add-version-form',
		'enableClientValidation'=>true,
	//	'enableAjaxValidation'=>true,
		'htmlOptions'=>array(
			'enctype'=>'multipart/form-data',
		//	'onsubmit'=>'handle=self.setInterval("showUpload()",500);',
		//	'target'=>'upload_frame',
		),
		));
?>

<input id="progress_key" name="APC_UPLOAD_PROGRESS" type="hidden" value="<?php echo $latestVersion->guid; ?>" />
<?php echo $form->fileField($model, 'uploadedFile');?>
<?php echo $form->hiddenField($model, 'start_time', array('value'=>date("Y-m-d H:i:s"))); ?>
<br />
	<span id="uploadprogressbar" class="progressbar">0%</span>
<br />
<?php echo CHtml::label('Please input its symbolic name:', ''); ?>
<br />
<?php echo $form->textField($model, 'symbolic_name'); ?>
<?php echo $form->error($model, 'symbolic_name'); ?>
<br />
<?php echo CHtml::label('Please input its description:', ''); ?>
<br />
<?php echo $form->textArea($model, 'description', array('rows'=>10, 'cols'=>30)); ?>
<?php echo $form->error($model, 'description'); ?>
<br />
<?php echo "Protected By Hash: "; ?>
<?php echo $form->checkBox($model, 'protected_by_hash'); ?>
<br /><br />
<?php echo CHtml::submitButton('Upload');?>

<?php $this->endWidget(); ?>
<?php echo CHtml::link('Back', Yii::app()->request->baseUrl."/manage/viewList?guid=".$latestVersion->guid); ?>

<iframe style="display: none" id="upload_frame" name="upload_frame"></iframe>

